/*
	File:	video/model/Bone.hpp
	Date:	2013-06-01
	Author:	Asteroth
*/


#ifndef __ZEN_MODEL_BONE_HPP__
#define __ZEN_MODEL_BONE_HPP__

#include "../Material.hpp"
#include "../../math.hpp"
#include "Animation.hpp"
#include "Mesh.hpp"

namespace zen {

	namespace video {

		class ShaderManager;

		namespace model {

			class Bone {

			public:

				Bone();
				Bone(const Bone &other);
				~Bone();
				
				Bone& operator = (const Bone &other);

				std::string getName() const { return name; }
				std::string getParentName() const { return parentName; }
				std::string getMaterialName() const { return materialName; }

				glm::mat4 getLocalView() const { return localView; }
				glm::mat4 getGlobalView() const { return globalView; }

				glm::sint getIndex() const { return index; }
				void setIndex(glm::sint index) { this->index = index; }

				glm::sint getParentIndex() const { return parentIndex; }
				void setParentIndex(glm::sint parentIndex) { this->parentIndex = parentIndex; }

				glm::sint getMaterialIndex() const { return materialIndex; }
				void setMaterialIndex(glm::sint materialIndex) { this->materialIndex = materialIndex; }

				glm::sint getMeshIndex() const { return meshIndex; }
				void setMeshIndex(glm::sint meshIndex) { this->meshIndex = meshIndex; }

				glm::sint getAnimationIndex() const { return animationIndex; }
				void setAnimationIndex(glm::sint animationIndex) { this->animationIndex = animationIndex; }

				void setAnimationFrame(Animation** animations, glm::uint start, glm::uint end, glm::uint position, AnimType type = AnimTypeOnce, glm::float32 speed = 1.0);
				
				void free() { free(true); }

				void update(int interval, Bone** bones, Animation** animations);
				void draw(const glm::mat4 &parentView, ShaderManager* materialShaderManager, Mesh** meshes, Material* materials) const;

				bool loadResource(jsl::Node* node, std::vector<Mesh*> &meshes, std::vector<Animation*> &animations);

				
			private:

				std::string			name;
				std::string			parentName;
				std::string			materialName;

				glm::mat4           localView;
				glm::mat4           globalView;

				AnimationFramer		animation;
				
				glm::sint			index;
				glm::sint			parentIndex;
				glm::sint			materialIndex;
				glm::sint			meshIndex;
				glm::sint			animationIndex;

				void init();
				void free(bool reinitialize);


			};


		} // namespace model

	} // namespace video

} // namespace zen

#endif
